package com.eastedu.superise.handler.question.handler.answer;

import java.util.HashMap;
import java.util.Map;

/**
 * √,×
 * 正确,错误
 *
 * @author ZhenZhong
 */
public class SpecialCharacter4Converter extends AbstractAsciiConverter implements AsciiConverter {

    private final Map<Integer, Integer> characterintegermap = new HashMap<>();

    {
        characterintegermap.put(8730, 1);
        characterintegermap.put(215, 0);
        characterintegermap.put(58321, 1);
        characterintegermap.put(73992, 0);
        characterintegermap.put(48, 0);
        characterintegermap.put(26159, 1);
        characterintegermap.put(21542, 0);
        characterintegermap.put(23545, 1);
        characterintegermap.put(38169, 0);
        characterintegermap.put(1703952, 1);
        characterintegermap.put(264241, 0);
        characterintegermap.put(448, 1);
        characterintegermap.put(523, 0);
        characterintegermap.put(10004, 1);
        characterintegermap.put(10006, 0);
    }

    @Override
    public boolean isSupported(String input) {
        int number = stingToNumber(input);
        return characterintegermap.containsKey(number);
    }


    @Override
    protected int doConvert(String input) {
        int number = stingToNumber(input);
        return characterintegermap.get(number);
    }

    @Override
    protected int getCharStartFlag() {
        return 0;
    }

    @Override
    protected int getCharEndFlag() {
        return 0;
    }


    private int stingToNumber(String letter) {
        int length = letter.length();
        int num = 0;
        int number = 0;
        for (int i = 0; i < length; i++) {
            char ch = letter.charAt(i);
            num = (int) (ch);
            number += num;
        }
        return number;
    }
}
